package com.majun.controller;

import com.alibaba.fastjson2.JSON;
import com.majun.service.RsaService;
import com.majun.vo.req.LoginReqVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author majun
 * @date 2025/05/14
 */
@Controller
@Slf4j
public class LoginController {

    @Resource
    private RsaService rsaService;

    @GetMapping("/login")
    public String login(Model model){
        model.addAttribute("msg", "RSA前端加密，后端解密测试");
        return "login";
    }

    @PostMapping(value = "/login")
    @ResponseBody
    public String login(@RequestBody LoginReqVO loginReqVO) throws Exception {
        log.info("loginReqVO:{}", JSON.toJSONString(loginReqVO));
        //解密后的密码
        String password = rsaService.decryptWithPrivate(loginReqVO.getPassword());
        log.info("解密后密码，password:{}", password);
        return "OK";
    }
}
